//
//  NSString+CNExtension.h
//
//  Created by 孟瑞瑞 on 19/3/13.
//  Copyright © 2019年 CSDN. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface NSString (CNExtension)

#pragma mark - size calculation

- (CGSize)cn_sizeForFont:(UIFont *)font;
- (CGSize)cn_sizeForFont:(UIFont *)font maxSize:(CGSize)size;

- (CGFloat)cn_widthForFont:(UIFont *)font;
- (CGFloat)cn_widthForFont:(UIFont *)font maxWidth:(CGFloat)maxWidth;

- (CGFloat)cn_heightForFont:(UIFont *)font width:(CGFloat)width;
- (CGFloat)cn_heightForFont:(UIFont *)font maxSize:(CGSize)size;
- (CGFloat)cn_heightForFont:(UIFont *)font width:(CGFloat)width lineSpacing:(CGFloat)lineSpacing;

/*!
 *
 * Encodes the string for use in a URL.
 *
 * @returns The string encoded for use in a URL
 *
 * @available Available in Singly iOS SDK 1.0.0 and later.
 *
 **/
- (NSString *)URLEncodedString;

/*!
 *
 * Decodes the string if it was encoded for us in a URL.
 *
 * @returns The decoded string
 *
 * @available Available in Singly iOS SDK 1.1.0 and later.
 *
 **/
- (NSString *)URLDecodedString;

// 截取字符串方法封装
- (NSString *)subStringFrom:(NSString *)startString to:(NSString *)endString;

-(BOOL)isBlank;
-(BOOL)isValid;
- (NSString *)removeWhiteSpacesFromString;

// 比较字符串不区分大小写
- (BOOL)isSameWithString:(NSString *)str;
- (NSUInteger)countNumberOfWords;
- (BOOL)containsString:(NSString *)subString;
- (BOOL)isBeginsWith:(NSString *)string;
- (BOOL)isEndssWith:(NSString *)string;

- (NSString *)replaceCharcter:(NSString *)olderChar withCharcter:(NSString *)newerChar;
- (NSString*)getSubstringFrom:(NSInteger)begin to:(NSInteger)end;
- (NSString *)addString:(NSString *)string;
- (NSString *)removeSubString:(NSString *)subString;

- (BOOL)containsOnlyLetters;
- (BOOL)containsOnlyNumbers;
- (BOOL)containsOnlyNumbersAndLetters;
- (BOOL)isInThisarray:(NSArray*)array;

+ (NSString *)getStringFromArray:(NSArray *)array;
- (NSArray *)getArray;

+ (NSString *)getMyApplicationVersion;
+ (NSString *)getMyApplicationName;

- (NSData *)convertToData;
+ (NSString *)getStringFromData:(NSData *)data;

- (BOOL)isValidEmail;
- (BOOL)isVAlidPhoneNumber;
- (BOOL)isValidUrl;

- (BOOL)isValidateEmail;//邮箱符合性验证。
- (BOOL)isNumber;//全是数字。
- (BOOL)isEnglishWords;//验证英文字母。
- (BOOL)isValidatePassword;//验证密码：6—16位，只能包含字符、数字和 下划线。
- (BOOL)isChineseWords;//验证是否为汉字。
- (BOOL)isInternetUrl;//验证是否为网络链接。
- (BOOL)isPhoneNumber;//验证是否为电话号码。正确格式为：XXXX-XXXXXXX，XXXX-XXXXXXXX，XXX-XXXXXXX，XXX-XXXXXXXX，XXXXXXX，XXXXXXXX
- (BOOL)isElevenDigitNum;//判断是否为11位的数字
- (BOOL)isIdentifyCardNumber;//验证15或18位身份证。

+ (NSString *)getURLFromString:(NSString *)string; // 获取string中的url
+ (NSString *)getNumberString:(NSString *)string;

+ (NSString *)getPlainTextInHTML:(NSString *)html; //过滤掉html标签和css属性


// 时间格式化成00:00
+ (NSString*)formatTimeInterval:(NSTimeInterval)interval;
// 时间格式化成00:00:00

+ (NSString *)formatTimeShowHourInterval:(NSTimeInterval)interval ;
+ (NSString *)formatTimeAllHourInterval:(NSTimeInterval)interval;

@end
